package com.education.platform.api.controller.sys;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.education.platform.common.util.BeanUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.util.List;
import org.springframework.beans.BeanUtils;
import com.education.platform.api.service.AppTabService;
import org.springframework.validation.annotation.Validated;
import com.education.platform.api.vo.response.AppTabResponseVO;
import com.education.platform.api.vo.request.AppTabQueryVO;
import com.education.platform.api.vo.response.AppTabPageInfoVO;
import com.education.platform.dao.entity.AppTabDO;

/**
 * describe: app的tab栏和广告栏
 * @author :
 * @date: 2020-08-15 09:24:55.670
 **/
@RestController
@Api("广告通知")
@RequestMapping("appTab")
@Validated
public class AppTabController {

    private static final Logger LOGGER = LoggerFactory.getLogger(AppTabController.class);

    @Autowired
    private AppTabService appTabService;
    /**
     * 分页查询
     * @param appTabQueryVO 分页查询参数
     * @return 分页参数
     */
    @ApiOperation(value = "分页查询")
    @PostMapping("getPageList")
    public AppTabPageInfoVO selectPageList(@RequestBody @Valid AppTabQueryVO appTabQueryVO) {
        LOGGER.info( appTabQueryVO.toString());
        AppTabDO appTab = BeanUtil.convert(appTabQueryVO, AppTabDO.class);
        appTab.setStatus(true);
        appTab.setDeleted(false);
        Page<AppTabResponseVO> page = PageHelper.startPage(appTabQueryVO.getPageNum(), appTabQueryVO.getPageSize());
        List<AppTabDO> appTabList = appTabService.getList(appTab);
        AppTabPageInfoVO appTabPageInfo = new AppTabPageInfoVO();
        BeanUtils.copyProperties(page.toPageInfo(), appTabPageInfo);
        List<AppTabResponseVO> voList = BeanUtil.convert(appTabList, AppTabResponseVO.class);
        appTabPageInfo.setList(voList);

        return appTabPageInfo;
    }


}
